#include <stdio.h>
#include <stdlib.h>
#include "aimage.h"
#include "aimage_utils.h"
#include "aimage_ppm.h"

int main( int argc, char *argv[] )
{
	AIMAGE image;
	float rc, gc, bc;

	if ( argc != 4 && argc != 5 )
	{
		fprintf(stderr, "%s red%% green%% blue%% [in_file]\n", argv[0] );
		exit( 1 );
	}

	rc = atof( argv[1] );
	if ( rc < 0 || rc > 1 )
	{
		fprintf(stderr, "%s red%% must be between 0 and 1\n",
			argv[0] );
		exit( 1 );
	}

	gc = atof( argv[2] );
	if ( gc < 0 || gc > 1 )
	{
		fprintf(stderr, "%s green%% must be between 0 and 1\n",
			argv[0] );
		exit( 1 );
	}

	bc = atof( argv[3] );
	if ( bc < 0 || bc > 1 )
	{
		fprintf(stderr, "%s blue%% must be between 0 and 1\n",
			argv[0] );
		exit( 1 );
	}

	if ( argc == 5 )
	{
		AIMAGE_PPM_UTILS::load( image, argv[4] );
	}
	else
	{
		AIMAGE_PPM_UTILS::load( image, "stdin" );
	}

	AIU::colrange( image, rc, 1.0, gc, 1.0, bc, 1.0 );

	AIMAGE_PPM_UTILS::save( image, "stdout", true );
}

